<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Alap dolgok bekérése
include("../../class2.php");

// Ellenőrzés
if (e_QUERY) $id = (int)e_QUERY;
else header("Location: project_list.php");

include(e_PLUGIN."hotn_animelist/Languages/".e_LANGUAGE.".php");
include(e_PLUGIN."hotn_animelist/Languages/".e_LANGUAGE."_genre.php");
include(e_PLUGIN."hotn_animelist/Class/animelist_mysql.php");
include(e_PLUGIN."hotn_animelist/Class/animelist_options.php");

//beállítások ellenőrzése:
if ($HOTN_ANIMELIST_OPTIONS['forum_type'] <> "" || $HOTN_ANIMELIST_OPTIONS['download_type']<>"")
{
	include(e_PLUGIN."hotn_animelist/Class/forum_".$HOTN_ANIMELIST_OPTIONS['forum_type'].".php");
	$HOTN_ANIMELIST_FORUM = new hotn_animelist_forum();

	include(e_PLUGIN."hotn_animelist/Class/download_".$HOTN_ANIMELIST_OPTIONS['download_type'].".php");
	$HOTN_ANIMELIST_DOWNLOAD = new hotn_animelist_download();
}

// Project adatok frissítése
$sql->db_Update("hotn_animelist_project","`project_request` = `project_request` + 1 WHERE `project_id` = '".$id."'");

// Project adatok lekérdezése
$project = $HOTN_ANIMELIST_DOWNLOAD->hotn_animelist_download_get_one_project($id);

// Oldal címe
define("e_PAGETITLE",HOTN_ANIMELIST_PROJECT_VIEW_TITLE.$project['project_name']);
$title = HOTN_ANIMELIST_PROJECT_VIEW_TITLE.$project['project_name'];
// Dátum kiíró
$gen = new convert;

// Foot js

//$footer_js[] = e_PLUGIN_ABS."hotn_animelist/Class/prototype.js";
//$footer_js[] = e_PLUGIN_ABS."hotn_animelist/Class/scriptaculous.js?load=effects,builder";
$footer_js[] = e_PLUGIN_ABS."hotn_animelist/Class/js/jquery.js";
$footer_js[] = e_PLUGIN_ABS."hotn_animelist/Class/js/lightbox.js";
$footer_js[] = e_PLUGIN_ABS."hotn_animelist/Class/js/script.js";

$text_project_content = "
<script>
var hotn_animelist_project_id = ".$id.";
</script>
";

// eplug css
$eplug_css[] = e_PLUGIN_ABS."hotn_animelist/Class/lightbox.css";

// hotn_animelist css file beolvasása
if (file_exists(THEME."hotn_animelist/animelist.css")) $eplug_css[] = THEME."hotn_animelist/animelist.css";
else $eplug_css[] = e_PLUGIN_ABS."hotn_animelist/Class/animelist.css";

// Project állapota
if ($project['project_mode'] == "active") $themp = HOTN_ANIMELIST_ANIMETYPE_ACTIVE;
if ($project['project_mode'] == "finished") $themp = HOTN_ANIMELIST_ANIMETYPE_FINISHED;
if ($project['project_mode'] == "planned") $themp = HOTN_ANIMELIST_ANIMETYPE_PLANNED;
if ($project['project_mode'] == "passive") $themp = HOTN_ANIMELIST_ANIMETYPE_PASSIVE;
if ($project['project_mode'] == "dropped") $themp = HOTN_ANIMELIST_ANIMETYPE_DROPPED;
$project['project_mode'] = "<li class='hotn_animelist_project_view_mode'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_MODE."</span><a href='project_list.php?".$project['project_mode'].".all.10.0'>".$themp."</a></li>";

// Kezdés és befejezés dátuma
if ($project['project_date_end'] == 0) $project['project_date_end'] = HOTN_ANIMELIST_PROJECT_ACTIVE_PROJECT;
else $project['project_date_end'] = $gen->convert_date($project['project_date_start'],"long");
$project['project_date_end'] = "<li class='hotn_animelist_project_view_date_end'><span>".HOTN_ANIMELIST_PROJECT_PROJECT_DATE_END."</span>".$project['project_date_end']."</li>";
$project['project_date_start'] = "<li class='hotn_animelist_project_view_date_start'><span>".HOTN_ANIMELIST_PROJECT_PROJECT_DATE_START."</span>".$gen->convert_date($project['project_date_start'],"long")."</li>";

// Munkatársak
$sql->db_Select("hotn_animelist_team as team, ".MPREFIX."user as user","user.user_id, user.user_name","WHERE user.user_id = team.team_id ORDER BY user_name ASC","non-default");
while($row = $sql->db_Fetch())
{
	$HOTN_ANIMELIST_TEAM[$row['user_id']] = $row['user_name'];
}

$team_project_row = array(
	"project_translator" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_TRANSLATOR,
	"project_karaoke" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_KARAOKE,
	"project_format" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_FORMAT,
	"project_manga_format" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_MANGA_FORMAT,
	"project_video" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_VIDEO,
	"project_lector" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_LECTOR,
	"project_timer" => HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_TIMER
);

foreach ($team_project_row as $id => $value)
{
	if ( ($project[$id] <> "") || ($project[$id."_other"]<>"") )
	{
		$user_links = array();
		foreach (explode("%",$project[$id]) as $user_explode)
		{
			$user_links[] = "<a href='project_team.php?".$user_explode."'>".$HOTN_ANIMELIST_TEAM[$user_explode]."</a>";
		}
		
		$user_links = implode(", ",$user_links);
		
		if ($project[$id."_other"]<>"")
		{
			if ($project[$id] <> "")
			{
				$user_links .= ", ";
			}
			$user_links .= $project[$id."_other"];
		}
		
		$project[$id] = "
		<li class='hotn_animelist_project_view_team'>
			<span>".$value."</span>
			".$user_links."
		</li>
		";
	}
}

// Genre
$genre = "";
$sql->db_Select("hotn_animelist_genre","*","`project_id` = '".$project['project_id']."' GROUP BY genre_id");
while($row = $sql->db_Fetch())
{
	$genre[] = "<a href='project_list.php?active.all.10.0.".$row['genre_id']."'>".$HOTN_ANIMELIST_GENRE[$row['genre_id']]."</a>";
}
if ($genre<>"") $genre = "<li class='hotn_animelist_project_view_genre'><span>".HOTN_ANIMELIST_PROJECT_VIEW_GENRE."</span> ".implode(", ",$genre)."</li>";

// Fórum
if ($project['project_forum'] <> 0) 
	$project['project_forum'] = "
		<li>
			<a href='".e_PLUGIN."forum/forum_viewtopic.php?".$row['project_forum']."'><b>".AL_LAN_74."</b></a>
		</li>";
else $project['project_forum'] = "";

// Project neve
$project['project_name'] = "<li class='hotn_animelist_project_view_title'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_TITLE."</span>".$project['project_name']."</li>";

// project angol neve
if ($project['project_eng_name'] <> "")
{
	$project['project_eng_name'] = "<li class='hotn_animelist_project_view_eng_name'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_ENG_TITLE."</span>".$project['project_eng_name']."</li>";
}

// Project magyar neve
if ($project['project_hun_name'] <> "")
{
	$project['project_hun_name'] = "<li class='hotn_animelist_project_view_hun_name'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_HUN_NAME."</span>".$project['project_hun_name']."</li>";
}

// Egyéb nevek
if ($project['project_other_name'] <> "")
{
	$project['project_other_name'] = "<li class='hotn_animelist_project_view_other_name'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_OTHER_TITLE."</span><div style='padding-left: 30px'>".str_replace("\n","<br />",$project['project_other_name'])."</div>	</li>";
}

// Anime típus kiírása
if ($project['project_type'] <> "manga")
{
	switch ($project['project_anime_type'])
	{
		case "tv": $project['project_anime_type'] = HOTN_ANIMELIST_ANIMETYPE_TV;
			break;
		case "ova": $project['project_anime_type'] = HOTN_ANIMELIST_ANIMETYPE_OVA;
			break;
		case "movie": $project['project_anime_type'] = HOTN_ANIMELIST_ANIMETYPE_MOVIE;
			break;
		case "ona": $project['project_anime_type'] = HOTN_ANIMELIST_ANIMETYPE_ONA;
			break;
		case "special": $project['project_anime_type'] = HOTN_ANIMELIST_ANIMETYPE_SPECIAL;
			break;
	}
	
	$project['project_anime_type'] = "<li class='hotn_animelist_project_view_anime_type'><span>".HOTN_ANIMELIST_PROJECT_VIEW_PROJECT_ANIME_TYPE."</span>".$project['project_anime_type']."</li>"; 
}
else
{
	// Ez egy manga, szóval nincs szükség típus kiírása
	$project['project_anime_type'] = "";
}

// Project típusa
if ($project['project_type'] == "anime") $themp = HOTN_ANIMELIST_DEFAULT_ANIME;
if ($project['project_type'] == "manga") $themp = HOTN_ANIMELIST_DEFAULT_MANGA;
$project['project_type'] = "<li class='hotn_animelist_project_view_type'><span>".HOTN_ANIMELIST_PROJECT_PROJECT_TYPE."</span><a href='project_list.php?all.".$project['project_type'].".10.0'>".$themp."</a></li>";

// Fut-e még a cucc?
if ($project['project_length'] == 0) $project['project_length'] = HOTN_ANIMELIST_PROJECT_ACTIVE_PROJECT;

$project['project_files'] = "<li class='hotn_animelist_project_view_files'><span>".HOTN_ANIMELIST_PROJECT_PROJECT_FILE."</span>".$project['project_files']." / ".$project['project_length']."</li>";

// Project megtekintése
$project['project_request'] = "<span>".HOTN_ANIMELIST_PROJECT_PROJECT_REQUEST."</span>".$project['project_request'];

// Egyéb linkek
$project_other_link_text = array();

if ($project['project_anidb'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_anidb']."' target='_blank'>ANIDB</a> ]";
}

if ($project['project_animenewsnetwork'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_animenewsnetwork']."' target='_blank'>ANN</a> ]";
}

if ($project['project_animenewsnetwork_manga'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_animenewsnetwork_manga']."' target='_blank'>ANN</a> ]";
}

if ($project['project_animenfo'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_animenfo']."' target='_blank'>ANFO]/a> ]";
}

if ($project['project_mangahelpers'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_mangahelpers']."' target='_blank'>MH</a> ]";
}

if ($project['project_bakaupdates'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_bakaupdates']."' target='_blank'>BU</a> ]";
}

if ($project['project_mangaupdates'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_mangaupdates']."' target='_blank'>MU</a> ]";
}

if ($project['project_vndb'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_vndb']."' target='_blank'>VNDB</a> ]";
}

if ($project['project_vnet'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_vnet']."' target='_blank'>VNET</a ]>";
}

if ($project['project_animeaddicts'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_animeaddicts']."' target='_blank'>AA</a> ]";
}

if ($project['project_animgo'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_animgo']."' target='_blank'>ANIMGO</a> ]";
}

if ($project['project_mangahu'] <> "")
{
	$project_other_link_text[] = "[ <a href='".$project['project_mangahu']."' target='_blank'>MANGAHU</a> ]";
}

// Linkek összerakása
$project_other_link_text = implode(", ",$project_other_link_text);
if ($project_other_link_text <> "")
{
	$project['project_other_link'] = "<li class='hotn_animelist_project_view_other_link'><span>".HOTN_ANIMELIST_PROJECT_OTHER_LINK."</span>".$project_other_link_text."</li>";	
}
else
{
	$project['project_other_link'] = "";
}

// megjelenítés
$text_project_content .="
	<table class='hotn_animelist_project_view' style='width: 100%'>
		<tr>
			<td class='hotn_animelist_project_view_image'>
				<img src='".e_PLUGIN."hotn_animelist/Project/".$project['project_folder']."/".$project['project_image_reference']."' />
			</td>
			<td class='hotn_animelist_project_view_info'>
				<ul>
					".$project['project_name']."
					".$project['project_eng_name']."
					".$project['project_hun_name']."
					".$project['project_other_name']."
					
					".$project['project_type']."
					".$project['project_anime_type']."
					".$genre."
					".$project['project_files']."
					".$project['project_mode']."
					".$project['project_other_link']."
					
					".$project['project_translator']."
					".$project['project_karaoke']."
					".$project['project_format']."
					".$project['project_manga_format']."
					".$project['project_video']."
					".$project['project_lector']."
					".$project['project_timer']."
					".$project['project_forum']."
					
					".$project['project_date_start']."
					".$project['project_date_end']."
					<li class='hotn_animelist_project_download_view'>[ <a href='javascript:request(\"content\",".$project['project_id'].");'>".HOTN_ANIMELIST_PROJECT_PROJECT_VIEW."</a> ]</li>
					<li class='hotn_animelist_project_view_link_download'>[ <a href='javascript:request(\"download\",".$project['project_id'].");'>".HOTN_ANIMELIST_PROJECT_PROJECT_DOWNLOAD."</a> ]</li>
				</ul>
			</td>
		</tr>
		<tr>
			<td colspan='2' id='hotn_animelist_content' class='hotn_animelist_content'>
			</td>
		</tr>
	</table>
";

// Oldal megjelenítése
require_once(HEADERF);
$ns -> tablerender($title, $text_project_content, "");
require_once(FOOTERF);
?>
